<!--开关-->

<template>
  <div class="w-h-full" :style="{
    textAlign: 'center',
    lineHeight: $parent.$parent.layoutItem.layoutItemConfigData.height + 'px'
  }">
    <!--组件遮罩层，用于在设计器中显示-->
    <div v-if="shade" class="shade"></div>

    <i-switch v-model="value"
              :style="{
                transform: 'scale('+component.compConfigData.scaleValue+')'
              }"
              :size="component.compConfigData.size"
              @on-change="onChangeHandle"></i-switch>
  </div>
</template>

<script>

  import FuncCompMixin from '@/mixin/FuncCompMixin'
  import PnDesigner from '@/utils/PnDesigner'

  const _this = {
    name: 'SwitchComp', // 此名称必须填写，且必须与组件文件名相同
    mixins: [FuncCompMixin],
    attr: {
      version: '1.0',
      configDataTemp: Object.assign({

        size: 'large',
        scaleValue: 1,

        onChangeCode: ''

      }, PnDesigner.buildFuncCompGlobalField(), PnDesigner.buildFuncCompInteractionConfiguration([
        PnDesigner.buildFuncCompInteractionStreamItem('itemChange', [
          PnDesigner.buildFuncCompInteractionFieldsMapItem('value','', '值')
        ])
      ]))
    },
    data() {
      return {
        value: false
      }
    },
    mounted() {
      this.init();
    },
    methods: {
      init() { // 组价初始化函数，函数名必须使用init，不可更改
        this.initDatasource(() => {
          this.runCustomGlobalJsCode()
        }, (result) => {
          this.runCustomGlobalJsCode()
        });
      },

      onChangeHandle (value) {
        this.$PnDesigner.launchInteractionStream(this.component.compConfigData, 'itemChange', {value: value})
        eval(this.component.compConfigData.onChangeCode)
      }
    },
    computed: {}
  };

  export default _this
</script>

<style scoped>

</style>
